//
//  HBActivityDetailCtrl.m
//  HuoBao
//
//  Created by sky on 15/12/17.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBActivityDetailCtrl.h"

@interface HBActivityDetailCtrl ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *myWebView;
@property (nonatomic, strong) NSString *webUrl;


@end

@implementation HBActivityDetailCtrl

#pragma mark - system

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)buildLayout
{
    [super buildLayout];
    self.title = @"活动详情";
    self.myWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    self.myWebView.delegate = self;
    self.myWebView.backgroundColor = [LCCommon getColor:Main_BackGround_Color];
    self.myWebView.opaque = NO;
    self.webUrl = self.iteminfo.activityUrl;
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webUrl]]];
    [self.view addSubview:self.myWebView];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    [self.myWebView stopLoading];
    self.myWebView.delegate = nil;
    [self.myWebView removeFromSuperview];
    self.myWebView = nil;
}

#pragma mark - delegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    LLog(@"%@,%@",request.URL.absoluteString,self.webUrl);
    if ([request.URL.absoluteString isEqualToString:self.webUrl]||[request.URL.absoluteString isEqualToString:[NSString stringWithFormat:@"%@/",self.webUrl]])
    {
        [CustomLoadingView showHudToView:self.view];
    }
    return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [CustomLoadingView hideHudForView:self.view];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [CustomLoadingView hideHudForView:self.view];
}


@end
